<template>
	<view class="login_ctn">
		<!-- <view class="login_header" v-if="userName != ''">欢迎你！{{ userName }}</view> -->
		<!-- <view class="login_footer">
			<view class="footer_btn">
				<button type="default" @click="setCode" :disabled="!idNumber || !userCode" :class="userCode && idNumber?'active':''">登录</button>
			</view>
		</view> -->
	</view>
</template>

<script>
import service2 from '../salary/service/salaryService.js'
import service from '../../common/service/new_file.js';
import apiData from '../../common/utils/apiData.js';
export default {
	data() {
		return {
			userInforn: null,
			code: '',
			userName: ''
		};
	},
	methods: {
		setCode(code) {
			let _this = this;
			let app_code = this.$store.state.power
			//新增app_code，等于1现在的应用，2 工资条， 3 绩效
			let data = apiData.setUserCodeData(code,app_code);
			// alert(JSON.stringify(data))
			service.common(data, {
				success: function(res) {
					// alert('返回值'+JSON.stringify(res))
						uni.showToast({
							title:'登录成功'
						})
						let userInfo = res.data.VALUES[0];
						userInfo.token = res.data.TonKen;
						_this.userName = res.data.VALUES[0].user_name;
						uni.setStorageSync('user', JSON.stringify(userInfo));
						setTimeout(() => {
							uni.navigateTo({
								url: '../home/home'
							});
						}, 500);
						_this.getServiceLeaveType()
						_this.getWorkPeriod()
						_this.getServiceLeaveShift()
				},
				fail:err=>{
				},
				all: all => {}
			});
			
		},
		getWorkPeriod() {
			let _this = this;
			let data = apiData.setWorkPeriodData();
			service.common(data, {
				success: res => {
					let workPeriod = res.data.VALUES
					uni.setStorageSync('workPeriod',JSON.stringify(workPeriod))
				},
				fail: function(res) {
					uni.showToast({
						icon:'none',
						title:'未获取到班次类型，请重试！'
					})
				}
			});
		},
		getServiceLeaveShift(){
			let _this = this;
			let data = apiData.getLeaveTypeData("leaveshift",'1');
			let leaveTypeStr //返回的中文
			let leaveArr = []
			service.common(data, {
				success: function(res) {
					let leaveObj = res.data.VALUES[0];
					let leaveOption = [];
					for (let key in leaveObj) {
						leaveOption.push({
							value: key,
							label: leaveObj[key]
						});
					}
					uni.setStorageSync('leaveType',JSON.stringify(leaveOption))
				},
				fail: function(res) {
					uni.showToast({
						icon:'none',
						title:'未获取到班次类型，请重试！'
					})
				}
			});
		},
		getServiceLeaveType(){
			let _this = this;
			let data = apiData.getLeaveTypeData("leavetype",'1');
			let leaveTypeStr //返回的中文
			let leaveArr = []
			service.common(data, {
				success: function(res) {
					let leaveObj = res.data.VALUES[0];
					let leaveOption = [];
					for (let key in leaveObj) {
						leaveOption.push({
							value: key,
							label: leaveObj[key]
						});
					}
					uni.setStorageSync('leaveShift',JSON.stringify(leaveOption))
				},
				fail: function(res) {
					uni.showToast({
						icon:'none',
						title:'未获取到请假类型，请重试！'
					})
				}
			});
		},
		getCode() {
			this.code = '';
			this.code = this.getUrlCode('code'); // 截取code
			if (this.code == null || this.code ==undefined) {
				// 如果没有code，则去请求
				uni.showToast({
					icon:'none',
					title:'当前无法获取code'
				})
			} else {
				this.setCode(this.code);
			}
		},
		// 输入时设置data数据
		getUrlCode(variable) {
			// var url = window.location.search;
			//602326 601956 605555 602195 602191(李晓梅) cy(陈艳) 602325 602188(杨凌宏) 604984(张飞) 602191(离职) 605527
			// console.log() 602451
			// var query="&code=602325"
			var query=window.location.search.substring(1)
			var vars = query.split('&');
			for (var i = 0; i < vars.length; i++) {
				var pair = vars[i].split('='); 
				if (pair[0] == variable) {
					return pair[1];
				}
			}
		}
	},
	onLoad() {
		// this.getPk_psndoc()
		let obj = null
		uni.setStorageSync('leaveType',obj)
		uni.setStorageSync('leaveShift',obj)
		uni.setStorageSync('workPeriod',obj)
		uni.setStorageSync('user', obj);
		this.getCode();
	},
	onReady() {
	}
};
</script>
<style lang="scss">
.login_ctn {
	padding: 60rpx;

	.login_header {
		height: 42rpx;
		font-size: 42rpx;
		font-family: PingFangSC-Semibold, PingFang SC;
		font-weight: 600;
		color: #000000;
		line-height: 42rpx;
	}

	.login_middle {
		margin: 140rpx 0 0;

		.middle_ctn {
			margin-top: 40rpx;

			.middle_left {
				font-size: 32rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #000000;
			}

			.middle_right {
				margin-top: 40rpx;
				border-bottom: 2rpx solid #cfcfcf;

				input {
					margin-bottom: 16rpx;
					padding: 0 40rpx;
				}
			}
		}
	}

	.login_footer {
		margin-top: 420rpx;

		button {
			background-color: #86d5ff;
			color: #fff;
			border-radius: 92rpx;
		}

		.active {
			background-color: #118dfb;
		}
	}
}
</style>
